from selenium.webdriver.common.by import By
from base.mp.base import BasePage,BaseHandle


class LoginPage(BasePage):
    def __init__(self):
        super().__init__()
        self.mobile = By.XPATH, "//*[@placeholder='请输入手机号']"
        self.code = By.XPATH, "//*[@placeholder='验证码']"
        self.login_btn = By.CSS_SELECTOR, ".el-button--primary"

    def find_mobile(self):
        return self.get_element(self.mobile)

    def find_code(self):
        return self.get_element(self.code)

    def find_login_btn(self):
        return self.get_element(self.login_btn)


class LoginHandle(BaseHandle):
    def __init__(self):
        self.login_page = LoginPage()

    def input_mobile(self, mobile):
        self.input_text(self.login_page.find_mobile(), mobile)

    def input_code(self, code):
        self.input_text(self.login_page.find_code(), code)

    def click_login_btn(self):
        self.login_page.find_login_btn().click()


class LoginProxy():
    def __init__(self):
        self.login_handle = LoginHandle()

    def login(self, mobile, code):
        self.login_handle.input_mobile(mobile)
        self.login_handle.input_code(code)
        self.login_handle.click_login_btn()
